$(function () {
    $("#jqGrid").jqGrid({
        url: 'sys/generator/list',
        datatype: "json",
        colModel: [			
			{ label: '表名', name: 'tableName', width: 100, key: true },
			{ label: 'Engine', name: 'engine', width: 70},
			{ label: '表备注', name: 'tableComment', width: 100 },
			{ label: '创建时间', name: 'createTime', width: 100 }
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50,100,200],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

// var vm = new Vue({
// 	el:'#rrapp',
// 	data:{
// 		q:{
// 			tableName: null
// 		}
// 	},
// 	methods: {
// 		query: function () {
// 			$("#jqGrid").jqGrid('setGridParam',{
//                 postData:{'tableName': vm.q.tableName},
//                 page:1
//             }).trigger("reloadGrid");
// 		},
// 		generator: function() {
// 			var tableNames = getSelectedRows();
// 			if(tableNames == null){
// 				return ;
// 			}
//             location.href = "sys/generator/code?tables=" + tableNames.join();
// 		}
// 	}
// });

var vm = new Vue({
    el:'#rrapp',
    data:{
        q:{
            tableName: null,
            mainPath: '',
            package: '',
            moduleName:'',
            author: '',
            email:'',
            tablePrefix:''
        }
    },
    computed: {
        filterParamsStr: function () {
            var params = {}
            var paramsStr = ''
            if (this.q.mainPath) {
                params.mainPath = this.q.mainPath
            } else {
                delete params.mainPath
            }
            if (this.q.packagePath) {
                params.packagePath = this.q.packagePath
            } else {
                delete params.packagePath
            }
            if (this.q.moduleName) {
                params.moduleName = this.q.moduleName
            } else {
                delete params.moduleName
            }
            if (this.q.author) {
                params.author = this.q.author
            } else {
                delete params.author
            }
            if (this.q.email) {
                params.email = this.q.email
            } else {
                delete params.email
            }
            if (this.q.tablePrefix) {
                params.tablePrefix = this.q.tablePrefix
            } else {
                delete params.tablePrefix
            }
            console.log(params)
            for(var key in params) {
                paramsStr += '&' + key + '=' + params[key]
            }
            return paramsStr
        }
    },
    methods: {
        query: function () {
            $("#jqGrid").jqGrid('setGridParam',{
                postData:{'tableName': vm.q.tableName},
                page:1
            }).trigger("reloadGrid");
        },
        generator: function() {
            var tableNames = getSelectedRows();
            if(tableNames == null){
                return ;
            }

            // console.log("sys/generator/code?tables=" + tableNames.join()+ this.filterParamsStr)

            location.href = "sys/generator/code?tables=" + tableNames.join()+ '&'+ this.filterParamsStr;
        }
    }
});

